package com.hylanda.pb.service;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.hylanda.pb.dao.TableSqlDao;
import com.hylanda.pb.entity.TableSql;
import com.hylanda.pb.model.TableSqlQo;

/** 
 * @author zhangy
 * @E-mail:blackoon88@gmail.com 
 * @qq:846579287
 * @version created at：2018年2月23日 上午9:44:31 
 * note
 */
@Service
public class TableSqlService {
	@Autowired
    private TableSqlDao tableSqlDao;
	
	public TableSql findById(Long id) {
		return tableSqlDao.findEntity(id);
	}

	public String findByName(String name){
		return tableSqlDao.findByName(name);
	}
	
	public TableSql create(TableSql entity) {
		  return tableSqlDao.save(entity);
	}

	public int update(TableSql entity) {
		return tableSqlDao.update(entity);
	}

	public int delete(Long id) {
		return tableSqlDao.delete(id);
	}

	public Page<TableSql> findPage(TableSqlQo reportFileQo){
		Pageable pageable = new PageRequest(reportFileQo.getPage(), reportFileQo.getSize(),Sort.Direction.DESC, "id");
		Map<String,Object> fieldsFilter=null;
		if(!StringUtils.isEmpty(reportFileQo.getTableName())){
			fieldsFilter=new HashMap<String, Object>();
			fieldsFilter.put("tableName", reportFileQo.getTableName());
		}
			
		Page<TableSql> page=tableSqlDao.findPage(pageable,TableSql.class,fieldsFilter);
		return page;
	}
	
}
